package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingItemDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public  PageResponse<NursingProjectVo> getNursingProjectList(NursingProjectDto nursingDto) {
        PageHelper.startPage(nursingDto.getPageNum(),nursingDto.getPageSize());
        Page<NursingProjectVo> pageList = nursingProjectMapper.getNursingProjectList(nursingDto);
        return PageResponse.of(pageList, NursingProjectVo.class);
    }

    @Override
    public void addNursingProject(NursingItemDto nursingItemDto) {
        NursingProject nursingProject = BeanUtil.copyProperties(nursingItemDto, NursingProject.class);
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    @Override
    public NursingProjectVo getNursingProjectById(Long id) {
        return  nursingProjectMapper.getNursingProjectById(id);
    }

    @Override
    public void updateNursingProject(NursingItemDto nursingItemDto) {
        NursingProject nursingProject = BeanUtil.copyProperties(nursingItemDto, NursingProject.class);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    @Override
    public void deleteNursingProject(Long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    @Override
    public void updateNursingProjectStatus(Long id, Integer status) {
        nursingProjectMapper.updateNursingProjectStatus(id,status);
    }

    @Override
    public List<NursingProjectVo> getAllNursingProject() {
        return nursingProjectMapper.getAllNursingProject();
    }
}
